package br.com.ps.bombertournament.game;

import java.util.Map;

/**
 * Responsible to create a collision between two game objects
 * 
 * @author Rennan Stefan Boni - rennanboni@gmail.com
 */
public class VolumeCollisionEngine implements CollisionEngine {
	
	@Override
	public void collision(Map<Integer, Layer> layers) {
		if (layers != null) {
			for (Integer key : layers.keySet()) {
				Layer layer = layers.get(key);
				
				BaseGameObject[] objects = layer.getQueueRender().toArray(new BaseGameObject[0]);
				for (int mainIndex = 0; mainIndex < objects.length; mainIndex++) {
					
					for (int secondIndex = 0; secondIndex < objects.length; secondIndex++) {
						if (objects[mainIndex] != objects[secondIndex]
								&& objects[mainIndex].getVolume() != null
								&& objects[secondIndex].getVolume() != null) {
							if (objects[mainIndex].instercept(objects[secondIndex])) {
								objects[mainIndex].onCollision(objects[secondIndex]);
							}
						}
					}
				}
			}
		}
	}
}
